﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Model;
using University.Workshop.Business;
using University.Workshop.WinApp.Main;

[assembly: CLSCompliant(true)]

namespace University.Workshop.WinApp.LogOn
{
    public partial class FormLogOn : Form
    {
        UserLogOn user=UserLogOn.Instance;
        LogOnBusiness log = new LogOnBusiness();
        public FormLogOn()
        {
            InitializeComponent();
        }

        private void btn_Ok_Click(object sender, EventArgs e)
        {
            try
            {
                user = log.Authentication(Acount.Text, Password.Text);
                MessageBox.Show(this, "Bienvenido " + user.Surname1 + " " + user.Surname2 + " " + user.Name, "Acceso correcto", MessageBoxButtons.OK,
                    MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,
                    MessageBoxOptions.RightAlign);
                FormMainView main = new FormMainView();
                this.Visible = false;
                main.ShowDialog();
                user = null;
                this.Close();

            }
           
            catch (BusinessException error)
            {
                MessageBox.Show(this, error.Message, "Error Log On!!!", MessageBoxButtons.OK,
                    MessageBoxIcon.Question, MessageBoxDefaultButton.Button1,
                    MessageBoxOptions.RightAlign);
            }
            Acount.Text = string.Empty;
            Password.Text = string.Empty;
        }

        private void Numbers(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar)) {
                
                e.Handled = false;
            }
            else
            {
                e.Handled=true;
            }
        }
        private void NumbersLetters(object sender, KeyPressEventArgs e)
        {
            if (char.IsDigit(e.KeyChar) || char.IsControl(e.KeyChar)||char.IsLetter(e.KeyChar))
            {

                e.Handled = false;
            }
            else
            {
                e.Handled = true;
            }
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
